package ystp.service;


import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.log4j.net.SyslogAppender;
import org.springframework.stereotype.Service;
import ystp.dao.ShengchanqiyelinxuanMapper;
import ystp.model.Kangjunyaowu;
import ystp.model.KangjunyaowuExample;
import ystp.model.Shengchanqiyelinxuan;
import ystp.model.ShengchanqiyelinxuanExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ShengchanqiyelinxuanService {

    @Resource
    ShengchanqiyelinxuanMapper ddMapper;

    public boolean isexistByxiangmuId(String xiangmuId){
        ShengchanqiyelinxuanExample mmExample=new ShengchanqiyelinxuanExample();
        ShengchanqiyelinxuanExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.selectByExample(mmExample).size()>0;
    }

    public Shengchanqiyelinxuan findOne(String id){
        return ddMapper.selectByPrimaryKey(id);
    }

    public boolean modify(Shengchanqiyelinxuan ppShengchanqiyelinxuan){
        return ddMapper.updateByPrimaryKeySelective(ppShengchanqiyelinxuan)==1;
    }

    public List<Map<String, Object>> chouQupinzhong(String pppinguileibie){
        return ddMapper.chouqupinzhong(pppinguileibie);
    }

    public List<Shengchanqiyelinxuan> findByPinzhongbianhao(String pppinzhongbianhao){
        ShengchanqiyelinxuanExample mmExample=new ShengchanqiyelinxuanExample();
        ShengchanqiyelinxuanExample.Criteria criteria=mmExample.createCriteria();
        criteria.andPinzhongbianhaoEqualTo(pppinzhongbianhao);
        return ddMapper.selectByExample(mmExample);
    }

    public List<Shengchanqiyelinxuan> findAllByXiangmuId(String xiangmuId){
        ShengchanqiyelinxuanExample mmExample=new ShengchanqiyelinxuanExample();
        ShengchanqiyelinxuanExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return ddMapper.selectByExample(mmExample);
    }

    public List<Map<String, Object>> findPinguiAll(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findPinguiAll(ppxiangmuId,mmStartIndex,ppPageSize);
    }
    public List<Map<String, Object>> findPinzhongAll(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findPinzhongAll(ppxiangmuId,mmStartIndex,ppPageSize);
    }

    public List<Map<String, Object>> findPinguiBySuijilunci(String ppxiangmuId,String ppSuijilunci,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findPinguiBySuijilunci(ppxiangmuId,ppSuijilunci,mmStartIndex,ppPageSize);
    }

    public List<Map<String, Object>> findPinzhongBySuijilunci(String ppxiangmuId,String ppSuijilunci,int ppPageIndex, int ppPageSize){
        System.out.println(ppxiangmuId+","+ppSuijilunci+","+ppPageIndex+","+ppPageSize);
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findPinzhongBySuijilunci(ppxiangmuId,ppSuijilunci,mmStartIndex,ppPageSize);
    }

    public List<Map<String, Object>> findPinzhongCustom(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findPinzhongCustom(ppxiangmuId,mmStartIndex,ppPageSize);
    }

    public List<Map<String, Object>> findPinguiByPinzhong(String ppxiangmuId,String mmPinzhongOne){
        return ddMapper.findPinguiByPinzhong(ppxiangmuId,mmPinzhongOne);
    }

    public List<Map<String, Object>> findPinguiFenlei(String ppxiangmuId,String mmPinzhongOne){
        return ddMapper.findPinguiFenlei(ppxiangmuId,mmPinzhongOne);
    }

    public List<Map<String, Object>> findPinguiByPinzhongLunci(String ppxiangmuId,String mmPinzhongOne,int ppLunci){
        return ddMapper.findPinguiByPinzhongLunci(ppxiangmuId,mmPinzhongOne,ppLunci);
    }

    public List<Map<String, Object>> findPinguiFenleiLunci(String ppxiangmuId,String mmPinzhongOne,int ppLunci){
        return ddMapper.findPinguiFenleiLunci(ppxiangmuId,mmPinzhongOne,ppLunci);
    }

    public List<Map<String, Object>> findShengchanqiyeByPingui(String ppxiangmuId,String mmPinguiOne){
        return ddMapper.findShengchanqiyeByPingui(ppxiangmuId,mmPinguiOne);
    }

    public List<Map<String, Object>> findShengchanqiyeByPinguiResult(String ppxiangmuId,String mmPinguiOne,String ppUserId,int ppLunci){
        return ddMapper.findShengchanqiyeByPinguiResult(ppxiangmuId,mmPinguiOne,ppUserId,ppLunci);
    }

/*    public List<Map<String, Object>> findShengchanqiyeByPinguiScore(String ppxiangmuId,String mmPinguiOne,int ppLunci){
        return ddMapper.findShengchanqiyeByPinguiScore(ppxiangmuId,mmPinguiOne,ppLunci);
    }*/

    public List<Map<String, Object>> findShengchanqiyeByPinguiScore(String ppxiangmuId,String mmPinguiOne){
        return ddMapper.findShengchanqiyeByPinguiScore(ppxiangmuId,mmPinguiOne);
    }

    public Integer getPinguiCount(String ppxiangmuId,String ppSuijilunci,int ppPageIndex, int ppPageSize) {
        Object mmCount = ddMapper.getPinguiCount(ppxiangmuId,ppSuijilunci,ppPageIndex,ppPageSize);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public boolean add (Shengchanqiyelinxuan ddShenchan){
        return ddMapper.insert(ddShenchan)==1;
    }

    public List<Shengchanqiyelinxuan> findAllBySuijilunci(String ppsuijilunci){
        ShengchanqiyelinxuanExample mmExample=new ShengchanqiyelinxuanExample();
        ShengchanqiyelinxuanExample.Criteria criteria=mmExample.createCriteria();
        criteria.andSuijilunciEqualTo(ppsuijilunci);
        return ddMapper.selectByExample(mmExample);
    }

//    public List<Shengchanqiyelinxuan> findAllBySuijilunciAndPinguileibie(String ppsuijilunci,String pppinguileibie){
//        ShengchanqiyelinxuanExample mmExample=new ShengchanqiyelinxuanExample();
//        ShengchanqiyelinxuanExample.Criteria criteria=mmExample.createCriteria();
//        criteria.andSuijilunciEqualTo(ppsuijilunci).andPinguileibieEqualTo(pppinguileibie);
//        return ddMapper.selectByExample(mmExample);
//    }
    public List<Map<String, Object>> findSmplingedPinguiBySuijilunciAndPinguileibie(String ppsuijilunci,String pppinguileibie){
        return ddMapper.findSmplingedPinguiBySuijilunciAndPinguileibie(ppsuijilunci,pppinguileibie);
    }

    public boolean deleteByxiangmuId(String xiangmuId){
        ShengchanqiyelinxuanExample mmExample=new ShengchanqiyelinxuanExample();
        ShengchanqiyelinxuanExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.deleteByExample(mmExample)>=0;
    }

    public int countJicai(String ppXiangmuId){
        ShengchanqiyelinxuanExample mmExample=new ShengchanqiyelinxuanExample();
        ShengchanqiyelinxuanExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(ppXiangmuId).andJicaiEqualTo("是");
        return ddMapper.countByExample(mmExample);
    }
    public int countTotal(String ppXiangmuId,String ppUserId, int ppLunci){
        Object mmCount = ddMapper.countTotal(ppXiangmuId,ppUserId,ppLunci);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public List<Shengchanqiyelinxuan> findJicai(String ppXiangmuId){
        ShengchanqiyelinxuanExample mmExample=new ShengchanqiyelinxuanExample();
        ShengchanqiyelinxuanExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(ppXiangmuId).andJicaiEqualTo("是");
        return ddMapper.selectByExample(mmExample);
    }

    public List<Map<String, Object>> findPinzhong(String ppxiangmuId,int ppLunci,String ppDrugname,
                                                  String ppGuigexuhao,
                                                  String ppJiyao,
                                                  String ppJicaiyao,
                                                  int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findPinzhong(ppxiangmuId,ppLunci,ppDrugname,ppGuigexuhao,ppJiyao,ppJicaiyao,mmStartIndex,ppPageSize);
    }
}
